package com.bootdo.acitvity.service.impl;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.bootdo.acitvity.annotation.DataSource;
import com.bootdo.acitvity.annotation.DataSourceNames;
import com.bootdo.acitvity.po.OaStudentDO;
import com.bootdo.acitvity.mapper.DeptDao;
import com.bootdo.acitvity.po.DeptDO;
import com.bootdo.acitvity.mapper.OaStudentDao;
import com.bootdo.acitvity.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
@Slf4j
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptDao deptDao;

    @Autowired
    private OaStudentDao oaStudentDao;

    @Override
    public DeptDO get(Long deptId) {
        return deptDao.get(deptId);
    }

    @Override
    @DataSource(DataSourceNames.ONE)
    public DeptDO test02(Long deptId) {
        return deptDao.get(deptId);
    }

    @Override
    @DataSource(DataSourceNames.TWO)
    public OaStudentDO getStuent(Long id) {
        return oaStudentDao.get(id);
    }

    @Override
    @SentinelResource(value = "sayHello", fallback = "fallBackError", blockHandler = "blockHandlerError")
    public String helloSentinel(Map<String, Object> params) {
        return "success";
    }

    public String blockHandlerError(Map<String, Object> params, BlockException e) {
        return "触发限流，返回为空";
    }

    public String fallBackError(Map<String, Object> flag) {
        return "触发熔断，返回为空";
    }
}
